package com.zxy.h2demo.business.dao.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.ximalaya.live.dao.BaseDao;
import com.zxy.h2demo.business.dao.ICrudTestDao;
import com.zxy.h2demo.business.model.Test;
import com.zxy.h2demo.business.model.TestExample;

@Repository
public class CrudTestDao extends BaseDao implements ICrudTestDao {
  private final Logger log = LoggerFactory.getLogger(getClass());

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  public CrudTestDao() {
    super();
  }

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  public int countByExample(TestExample example) {
    if (log.isDebugEnabled()) {
      log.debug("Count records from table TEST with example {}", example);
    }
    Integer count = (Integer) getSqlMapClientTemplate().queryForObject("test_TEST.ibatorgenerated_countByExample",
        example);
    return count;
  }

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  public int deleteByExample(TestExample example) {
    if (log.isDebugEnabled()) {
      log.debug("Delete records from table TEST with example {}", example);
    }
    int rows = getSqlMapClientTemplate().delete("test_TEST.ibatorgenerated_deleteByExample", example);
    return rows;
  }

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  public int deleteByPrimaryKey(Long id) {
    Test _key = new Test();
    _key.setId(id);
    if (log.isDebugEnabled()) {
      log.debug("Delete record {} from table TEST.", _key);
    }
    int rows = getSqlMapClientTemplate().delete("test_TEST.ibatorgenerated_deleteByPrimaryKey", _key);
    return rows;
  }

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  public void insert(Test record) {
    if (log.isDebugEnabled()) {
      log.debug("Insert record {} into table TEST.", record);
    }
    getSqlMapClientTemplate().insert("test_TEST.ibatorgenerated_insert", record);
  }

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  public void insertSelective(Test record) {
    if (log.isDebugEnabled()) {
      log.debug("Insert record {} into table TEST.", record);
    }
    getSqlMapClientTemplate().insert("test_TEST.ibatorgenerated_insertSelective", record);
  }

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  @SuppressWarnings("unchecked")
  public List<Test> selectByExample(TestExample example) {
    if (log.isDebugEnabled()) {
      log.debug("Query records from table TEST with example {}", example);
    }
    List<Test> list = getSqlMapClientTemplate().queryForList("test_TEST.ibatorgenerated_selectByExample", example);
    return list;
  }

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  public int updateByExampleSelective(Test record, TestExample example) {
    if (log.isDebugEnabled()) {
      log.debug("Update record into {} in table TEST with example {}", record, example);
    }
    UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
    int rows = getSqlMapClientTemplate().update("test_TEST.ibatorgenerated_updateByExampleSelective", parms);
    return rows;
  }

  /**
   * This method was generated by Apache iBATIS Ibator. This method corresponds to the database
   * table TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  public int updateByExample(Test record, TestExample example) {
    if (log.isDebugEnabled()) {
      log.debug("Update record into {} in table TEST with example {}", record, example);
    }
    UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
    int rows = getSqlMapClientTemplate().update("test_TEST.ibatorgenerated_updateByExample", parms);
    return rows;
  }

  /**
   * This class was generated by Apache iBATIS Ibator. This class corresponds to the database table
   * TEST
   *
   * @ibatorgenerated Fri Oct 14 17:36:07 CST 2016
   */
  protected static class UpdateByExampleParms extends TestExample {
    private Object record;

    public UpdateByExampleParms(Object record, TestExample example) {
      super(example);
      this.record = record;
    }

    public Object getRecord() {
      return record;
    }
  }
}